package com.zgh.leo.signin611;
//主类

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.hanks.htextview.HTextView;
import com.hanks.htextview.HTextViewType;
import com.zgh.leo.signin611.Sign_in.in_out;
import com.zgh.leo.signin611.resetting.repassword;
import com.zgh.leo.signin611.resetting.resignature;

public class MainActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener {


    HTextView dev_2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //初始化控件
        findViewById();

        //获取手机厂商型号
        devices();

        //初始化控件
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);


        /*//悬浮按钮 签到签离
        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "签到签离", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });*/

        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);

    }

    private void devices() {
        //手机厂商 型号
        String brand = Build.BRAND;
        String model = Build.MODEL;

        dev_2.setAnimateType(HTextViewType.LINE);
        if (brand.equals("Xiaomi") || brand.equals("xiaomi")) {
            dev_2.animateText("小米 "+model);
        }else if (brand.equals("Huawei") || brand.equals("HONOR")){
            dev_2.animateText("华为 "+model);
        }else if (brand.equals("OPPO")){
            dev_2.animateText("OPPO "+model);
        }

    }

    private void findViewById() {
        dev_2 = findViewById(R.id.device_2);
    }

    //两次返回键推出App
    private long firstPressedTime;
    public void onBackPressed() {
        if (System.currentTimeMillis() - firstPressedTime < 2000) {
            super.onBackPressed();
        } else {
            Toast.makeText(MainActivity.this, "再按一次退出", Toast.LENGTH_SHORT).show();
            firstPressedTime = System.currentTimeMillis();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    //右上角菜单  暂时没用
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return super.onOptionsItemSelected(item);
    }

    //侧边导航 打开各个页面
    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.in_out) {

            //setContentView(R.layout.activity_in_out);
            Intent intent = new Intent(MainActivity.this,in_out.class);
            startActivity(intent);
            Toast.makeText(this,"签到签离",Toast.LENGTH_SHORT).show();

        } else if (id == R.id.message_board) {

            //setContentView(R.layout.activity_message_board);
            Intent intent = new Intent(MainActivity.this, com.zgh.leo.signin611.message_board.class);
            startActivity(intent);
            Toast.makeText(this,"留言板",Toast.LENGTH_SHORT).show();

        } else if (id == R.id.repassword) {

            //setContentView(R.layout.activity_repassword);
            Intent intent = new Intent(MainActivity.this,repassword.class);
            startActivity(intent);
            Toast.makeText(this,"修改密码",Toast.LENGTH_SHORT).show();

        } else if (id == R.id.resignature) {

            //setContentView(R.layout.activity_resignature);
            Intent intent = new Intent(MainActivity.this,resignature.class);
            startActivity(intent);
            Toast.makeText(this,"修改签名",Toast.LENGTH_SHORT).show();

        }

        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        if (drawer!=null){
            drawer.closeDrawer(GravityCompat.START);
        }
        return true;
    }
}
